<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible" center width="60%">
    <el-form :model="dataForm" :inline="true" :rules="dataRule" ref="dataForm"
             @keyup.enter.native="dataFormSubmit()" label-width="180px">
      <el-form-item label="规则集合编号：" prop="droolsNum">
        <el-input v-model="dataForm.droolsNum" placeholder="规则集合编号"
                  clearable></el-input>
      </el-form-item>
      <el-form-item label="规则集合名称：" prop="droolsNum">
        <el-input v-model="dataForm.droolsName" placeholder="规则集合编号"
                  clearable></el-input>
      </el-form-item>
      <el-form-item label="用户名：" prop="userName">
        <el-input v-model="dataForm.userName" placeholder="用户名"
                  clearable></el-input>
      </el-form-item>
      <el-form-item label="密码：" prop="password">
        <el-input v-model="dataForm.password" placeholder="密码"
                  clearable></el-input>
      </el-form-item>
      <el-form-item label="链接前缀：" prop="url">
        <el-input v-model="dataForm.url" placeholder="链接前缀"
                  clearable></el-input>
      </el-form-item>
      <el-form-item label="认证类型：" prop="basicAuthentication">
        <el-input v-model="dataForm.basicAuthentication" placeholder="认证类型"
                  clearable></el-input>
      </el-form-item>
      <el-form-item label="包名：" prop="packageName">
        <el-input v-model="dataForm.packageName" placeholder="包名"
                  clearable></el-input>
      </el-form-item>
      <el-form-item label="版本号：" prop="version">
        <el-input v-model="dataForm.version" placeholder="版本号"
                  clearable></el-input>
      </el-form-item>
      <el-form-item label="jar包名：" prop="jarName">
        <el-input v-model="dataForm.jarName" placeholder="jar包名"
                  clearable></el-input>
      </el-form-item>
      <el-form-item label="创建时间：" prop="createTime">
        <el-input v-model="dataForm.createTime" placeholder="创建时间"
                  clearable></el-input>
      </el-form-item>
      <el-form-item label="更新时间：" prop="updateTime">
        <el-input v-model="dataForm.updateTime" placeholder="更新时间"
                  clearable></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button v-if="isAuth('project:rule:add')" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import {droolsBaseInfoOne, droolsBaseInfoSave} from '@/api/droolsBaseInfo'

    export default {
        data() {
            return {
                visible: false,
                dataForm: {
                    droolsNum: null,
                    droolsName:null,
                    userName: null,
                    password: null,
                    url: null,
                    basicAuthentication: null,
                    packageName: null,
                    version: null,
                    jarName: null,
                    createTime: null,
                    updateTime: null
                },
                dataRule: {
                    id:
                        [
                            {required: true, message: '主键', trigger: 'blur'}
                        ],
                    droolsNum:
                        [
                            {required: true, message: '规则集合编号', trigger: 'blur'}
                        ],
                    userName:
                        [
                            {required: true, message: '用户名', trigger: 'blur'}
                        ],
                    password:
                        [
                            {required: true, message: '密码', trigger: 'blur'}
                        ],
                    url:
                        [
                            {required: true, message: '链接前缀', trigger: 'blur'}
                        ],
                    basicAuthentication:
                        [
                            {required: true, message: '认证类型', trigger: 'blur'}
                        ],
                    packageName:
                        [
                            {required: true, message: '包名', trigger: 'blur'}
                        ],
                    version:
                        [
                            {required: true, message: '版本号', trigger: 'blur'}
                        ],
                    jarName:
                        [
                            {required: true, message: 'jar包名', trigger: 'blur'}
                        ],
                    createTime:
                        [
                            {required: true, message: '创建时间', trigger: 'blur'}
                        ],
                    updateTime:
                        [
                            {required: true, message: '', trigger: 'blur'}
                        ],
                }
            }
        },
        methods: {
            init(id) {
                if (id == null || id == undefined || id == "undefined") {
                    this.dataForm.id = null
                    this.dataForm.droolsNum = null
                    this.dataForm.droolsName = null
                    this.dataForm.userName = null
                    this.dataForm.password = null
                    this.dataForm.url = null
                    this.dataForm.basicAuthentication = null
                    this.dataForm.packageName = null
                    this.dataForm.version = null
                    this.dataForm.jarName = null
                    this.dataForm.createTime = null
                    this.dataForm.updateTime = null
                    this.visible = true
                    return;
                }
                this.dataForm.id = id
                this.visible = true
                this.$nextTick(()=>{
                    this.$refs['dataForm'].resetFields()
                }
            )
                if (this.dataForm.id) {
                    const param = {
                        'id': this.dataForm.id
                    }
                    const requestData = {
                        'requestData': param
                    }
                    droolsBaseInfoOne(requestData).then((res) =>{
                        this.dataListLoading = false
                        if(res.code == '0000'){
                           this.dataForm = res.responseData
                        }
                   }).catch((err) =>{})
                }
            },
            // 表单提交
            dataFormSubmit() {
                this.$refs['dataForm'].validate((valid) =>{
                    if(valid) {
                        const requestData = {
                            'requestData': this.dataForm
                        }
                        droolsBaseInfoSave(requestData).then((res)=>{
                            if(res.code == '0000'){
                            this.$message({
                                message: '操作成功',
                                type: 'success',
                                duration: 1000,
                                onClose:() =>{
                                this.visible = false
                                this.$emit('refreshDataList')
                            }})
                        }
                    }).catch((err) =>{})}
                }
            )
            }
        }
    }
</script>
